<?php

class SiteController extends BlankController
{

    public function actionIndex(){
        $this->data['message'] = null;
        $this->render("index",$this->data);
    }

    public function actionLogin(){

        $username = $_POST['username'];
        $password = $_POST['password'];

        $user = $this->connection->createCommand("select * from rk_user where username = :username")
            ->bindParam(":username",$username)
            ->queryRow();
        if($user==false){
            $this->data['message'] = AppCode::$error_userIsNotExist;
            $this->render("index",$this->data);
        }else{
            if($user['password'] == md5($password)){
                $loginUser = new CUserIdentity($username,$user['password']);
                Yii::app()->user->login($loginUser);
                $this->redirect("index.php?r=dashboard");
            }else{
                $this->data['message'] = AppCode::$error_userPasswordError;
                $this->render("index",$this->data);
            }
        }
    }

	public function actionLogout()
	{
		Yii::app()->user->logout();
		$this->redirect(Yii::app()->homeUrl);
	}
}